'''
Created on Jan 10, 2010

@author: Berin
'''
from surfacegrid import SurfaceGrid
import pygame
import tile
class TileSelectorGrid(SurfaceGrid):
	'''
	Represents the paint tile grid
	'''
	def __init__(self, windowHeight):
		'''
		Constructor
		'''
		SurfaceGrid.__init__(self, 0, 0, 0, 0, pygame.image.load("town1.png"))

		self.surface_setup(windowHeight)
		
	def draw(self, screen):
		'''
		Draws the Tiles
		'''
		SurfaceGrid.draw(self)
		
		'''
		Do other drawing below
		'''
		if self.tileset != None:
			self.mainSurface.blit(self.tileset, (0 - self.xPosition,0 - self.yPosition))
		
		for tiles in self.tileArray:
			self.mainSurface.blit(tiles.get_Surface()[0], (tiles.get_X() - self.xPosition, tiles.get_Y() - self.yPosition))
			pygame.draw.rect(self.mainSurface, tiles.get_color(), pygame.Rect(tiles.get_X() - self.xPosition, tiles.get_Y() - self.yPosition, 32, 32), 1)
	
	def surface_setup(self, windowHeight):
		if self.tileset != None:
			left = 0
			top = 0
			self.height = self.tileset.get_height()
			self.width = self.tileset.get_width()
			self.tileArray = []
			while top < self.tileset.get_height():
				while left < self.tileset.get_width():
					temp = self.tileset.subsurface(pygame.Rect(left, top, 32, 32)).copy()
					self.tileArray.append(tile.Tile((left, top), (32, 32), temp, None))
					left = left + 32
				left = 0
				top = top + 32	  
		
		self.surfaceHeight = ((windowHeight - 32) // 32) * 32
		self.mainSurface = pygame.Surface(((32*8), self.surfaceHeight))
		self.mainSurface.fill((255,255,255))